let myArr: string[] = ['Tom', 'Marry', 'Jack'] //数组
//字符串
let myname: string = 'xiatian'
//数字

//布尔值
let flag: boolean = true

//元组
let msg: [string, number, boolean] = ['hello', 22, true]

//所有类型
let anyArr: any[] = [1,2,3, 'hello']

//枚举
enum Color {
    red = 'red',
    black = 'black',
    pink = 'pink'
}


let likeColor: Color = Color.black

function getStr(str: string | number ) {
    if((str as string).length) {
        return (<string>str).length
    }else {
        return str.toString().length
    }
}

//定义接口 id为只读类型
interface IPerson {
    //readonly 只读
    readonly id : number
    userName: string
    age: number
    // ?代表 可选属性
    gender?: string
    
}

let person: IPerson = {
    id: 1,
    userName: "Tom",
    age: 27,

}

console.log(person)


console.log(getStr('hello world'))
console.log(getStr(1234))


console.log(likeColor)


console.log(myname)
console.log(myArr)
console.log(flag)
console.log(msg)
console.log(anyArr)